<%-- 
    Document   : imichat
    Created on : Jul 6, 2011, 6:15:38 PM
    Author     : M Bilal
--%>

<%@ page import="org.apache.log4j.Logger" %>

<% final Logger log = Logger.getLogger("JSP.INDEX");%>

<%@ page import="net.sourceforge.wurfl.core.*" %>
<%@ page import="java.util.*" %>
<%@ page import="wap.rockvilletech.portal.WapPortalBean" %>

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<%
	WURFLHolder wurflHolder = (WURFLHolder) getServletContext().getAttribute("net.sourceforge.wurfl.core.WURFLHolder");
	WURFLManager wurfl = wurflHolder.getWURFLManager();
	Device device = wurfl.getDeviceForRequest(request);
	WapPortalBean wpb = new WapPortalBean(device);
	String ua="",
        strBrand = "",
        strGsm = "",
        strModel = "",
        width = "",
        narrowStripFix = "", // height fix for the strips to be shown
        sImgFix = "", // size fix for the 4 main image links
        narrowStripCenterImageHeight = "36", // height fix for center part of the strip
        reommendationCenterTdWidth = "",
        newsCenterTdImgWidth = "",
        sectionHeaderPrefix = "", // variable used to hold the value of header name for sectionHeader.jspf, the name deternimes which strip to make
        context_Path = "",
        strApn = "", //Holds the apn of the user
        strIP = "",
        strSmsTag = "",
        strCallTag = "",
        paramsToRetain = "?",
        navLinksForLogging = "",
        strParameterSeparator = "?",
        thisPage = "Home", //Hold the name of the page the user is currently on
        bodyBgColor = "#dedfe1",
        bodyFgColor = "black",
        footerFgColor = "black",
        divBgColor = "#F2F2F2";


int wurfl_screenWidth = 0,
        wurfl_screenHeight = 0,
        singelColumnWidth = 150,
        mainButtonImgWidth = 100, // width for the icons that appear on the home page only
        newsCenterTdWidth = 0,
        xhtml_support_level = 0,
        newsImageWidth = 0,
        iconSize = 100, // size of the image icons (category images, download content image)
        catIcon=120,//size of tabs images(topwallpapers top animation etc)
        logo_width = 200, // width of the header logo, 200 is the image size
        w = -1, // user's Browser width
        comunityIcon=120;//communtiy Icon

boolean isUaSent = false,
        renderSingleColumn = false,
        isPercentWidthSupported = true, // To determine weather percent width is supported on table or not
        isNarrowStrip = false, // To determine weather to show narrow strip or wide one
        isWSent = false, // check if w is sent or not, it is mostly used in downloadable content display screens
        isIconStyle = false, // show portal in grid style
        iconStyle4InARowPatch = false,
        isFixWidthPatch = false, // fix for the phones which are causing issue in the header section
        isJSsupport=false,//is java script supported
        isODP=false;//odp portal

try {
    isODP =Boolean.valueOf(request.getParameter("odp")!=null?request.getParameter("odp"):"false");
    w = Integer.parseInt( request.getParameter("w"));
    //--out.println(w);
    isWSent = true;

    
} catch( Exception e ) {
}

try { ua = request.getParameter("ua"); isUaSent = true; } catch (Exception ex) { ua = ""; }
if (ua == null || ua.length() < 2) {
    ua = request.getHeader("User-Agent");
    isUaSent = false;
}

try { context_Path = request.getContextPath(); } catch(Exception ex) { context_Path = ""; }
if(context_Path.equalsIgnoreCase("/")) context_Path = "";


if(ua.contains("BlackBerry")) {
    // BlackBerry9000/4.6.0.266 was causing the problem, but we will cater for every black berry
    if(ua.contains("BlackBerry9000/4.6.0.266"))
        isFixWidthPatch = true;
        iconStyle4InARowPatch = true;
}

//Variables used to hold the values from DB
HashMap hmParams = null;
Vector v = null;
boolean isTopCat = false;
String app = "", strMainApp = "", strFooterImg = "footer.jpg", strFooterTxt = "",
        strHeaderImg = "header.jpg", strHeaderText = "", strParentCatId = "", strCss = "",
        strTitle = "", strAppMainCat = "", strSubCat = "", strAppCatType = "",
        strAppFOrS = "",tags="";

try {
    hmParams = new HashMap<String,String>();
    try {
        if(request.getParameter("app") == null) {
            if( request.getRequestURL().toString().contains("/content/") ) app = "Ufone_Content";
            else app = "Ufone";
        } else {
            app = ( request.getParameter("app").trim() );
            tags = app;

        }
    } catch( Exception e ) {
        if( request.getRequestURL().toString().contains("/content/") ) app = "Ufone_Content";
        else app = "Ufone";
    }

    hmParams.put("App", app);

    try {
        v = wpb.execCustomQuery("GetAppData", hmParams);
        if (v.size() < 1) {
            out.print("<h3>No Data available!.</h3>");
            return;
        } else {
            
            try {
                //session.setAttribute("app", ((Vector)v.get(0)).get(6).toString().trim()/*top category*/);
                strHeaderImg = ( ((Vector) v.get(0)).get(5) != null && !((Vector) v.get(0)).get(5).toString().trim().equalsIgnoreCase("") ) ? ((Vector) v.get(0)).get(5).toString().trim() : strHeaderImg;//cagegory header Image
                strMainApp = ((Vector) v.get(0)).get(6) != null ? ((Vector) v.get(0)).get(6).toString().trim() : ""; //get Main Application
                strFooterTxt = ((Vector) v.get(0)).get(7) != null ? ((Vector) v.get(0)).get(7).toString().trim() : ""; //footer text if any
                strHeaderText = ((Vector) v.get(0)).get(2) != null ? ((Vector) v.get(0)).get(2).toString().trim() : "";//cagegory top text
                strParentCatId = ((Vector)v.get(0)).get(8) != null ? ((Vector)v.get(0)).get(8).toString() : "";//cagegory parentid
                strAppFOrS =((Vector)v.get(0)).get(11) != null ? ((Vector)v.get(0)).get(11).toString() : "";//FilmOrsinger
                try { isTopCat = ((Vector)v.get(0)).get(8).toString().equalsIgnoreCase("0") ? true : false; } catch (Exception ex) {  }
            } catch (Exception e){
                }
            strCss = ((Vector) v.get(0)).get(1) != null ? ((Vector) v.get(0)).get(1).toString().trim() : ""; //if css available to apply
            strTitle = ((Vector) v.get(0)).get(9) != null ? ((Vector) v.get(0)).get(9).toString().trim() : "";//cagegory title
            try { strAppMainCat = ((Vector) v.get(0)).get(12).toString(); } catch (Exception ex) { strAppMainCat = ""; }
            try { strSubCat = ((Vector) v.get(0)).get(13).toString(); } catch (Exception ex) { strSubCat = ""; }//for not drawing header div
            try { strAppCatType = ((Vector) v.get(0)).get(10).toString(); } catch (Exception ex) { strAppCatType = ""; }
            //--try { strAppFOrS = ((Vector) v.get(0)).get(11).toString(); } catch (Exception ex) { strAppFOrS = ""; }
            strFooterImg = ((Vector) v.get(0)).get(4) != null ? ((Vector) v.get(0)).get(4).toString().trim() : strFooterImg;//cagegory footer Image
            
        }
    } catch (Exception ex) {
        //ex.printStackTrace();
    }
}
catch(Exception ex) {}
finally {
    hmParams = null;
    v = null;
}

boolean isXhtml = true;
boolean isHtml = true;
boolean isXTable = true;
boolean isTableSupport = true;

try {
    wurfl_screenWidth = Integer.parseInt(device.getCapability("resolution_width")); // Width from Wurfl //max_image_width
    wurfl_screenHeight = Integer.parseInt(device.getCapability("resolution_height")); // Width from Wurfl //max_image_height
    xhtml_support_level = Integer.parseInt(device.getCapability("xhtml_support_level")); // xhtml_support_level from Wurfl
    //resolution_height //max_image_width
/*
    out.print(" resolution_height="+wd.getCapabilityInt("resolution_height")+" resolution_width="+wd.getCapabilityInt("resolution_width")+"<br/>");
    out.print(" physical_screen_height="+wd.getCapabilityInt("physical_screen_height")+" physical_screen_width="+wd.getCapabilityInt("physical_screen_width")+"<br/>");
    out.print(" max_image_height="+wd.getCapabilityInt("max_image_height")+" max_image_width="+wd.getCapabilityInt("max_image_width"));
    out.print(" <br/>device_os="+wd.getCapability("device_os"));
    out.print(" device_os_version="+wd.getCapability("device_os_version"));
 */
    isPercentWidthSupported = device.getCapability("css_supports_width_as_percentage").equalsIgnoreCase("true");

    isXhtml = device.getCapability("preferred_markup").toLowerCase().contains("xhtml");
    isHtml = device.getCapability("preferred_markup").toLowerCase().startsWith("html_web");
    isXTable = device.getCapability("xhtml_table_support").equalsIgnoreCase("true");
    isJSsupport = device.getCapability("ajax_support_javascript").equalsIgnoreCase("true");

    strBrand = device.getCapability("brand_name");
    strModel = device.getCapability("model_name");
    
}
catch(Exception ex) {
    System.out.println(ex.getMessage());
}

isTableSupport = ( isHtml || (isXhtml && isXTable) );

try {
    strCallTag = device.getCapability("xhtml_make_phone_call_string");//get calling capability
} catch (Exception ex) { strCallTag = "tel:"; }

try {
    strSmsTag = device.getCapability("xhtml_send_sms_string");//get sms capability
} catch (Exception ex) { strSmsTag = "sms:"; }

if(xhtml_support_level < 3) {
    isPercentWidthSupported = false;
    isTableSupport = false;
}

if( strModel.equalsIgnoreCase("") && strBrand.equalsIgnoreCase("") ) {
    isTableSupport = true;
    isPercentWidthSupported = true;
    wurfl_screenWidth = 200;
    wurfl_screenHeight = 200;
}

width = String.valueOf(wurfl_screenWidth);

//iconSize = (int)(0.24 * wurfl_screenWidth); // 24% of the screen size
//catIcon = (int)(0.20 * wurfl_screenWidth); // 34% of the screen size
//comunityIcon=(int)(0.24 * wurfl_screenWidth);//per page 2 images
// Select Appropriate Header and Footer Images Depending upon the Size of the current device
if (wurfl_screenWidth >= 400) {
    iconSize = (int)(0.16 * wurfl_screenWidth); // 20% of the screen size
    logo_width = (int)(wurfl_screenWidth * 0.3);
    comunityIcon=(int)(0.16 * wurfl_screenWidth);//3 icon per row
} 
else if (wurfl_screenWidth >= 300 && wurfl_screenWidth < 400) {
    iconSize = (int)(0.24 * wurfl_screenWidth); // 30% of the screen size
    logo_width = (int)(wurfl_screenWidth * 0.3);
    comunityIcon=(int)(0.24 * wurfl_screenWidth);//3 icon per row
} 
else if (wurfl_screenWidth >= 200 && wurfl_screenWidth < 300) {
    iconSize = (int)(0.24 * wurfl_screenWidth); // 40% of the screen size 0.4
    logo_width = (int)(wurfl_screenWidth * 0.3);
    comunityIcon=(int)(0.24 * wurfl_screenWidth);//2 per row
}
else {
    iconSize = (int)(0.48 * wurfl_screenWidth); // 48% of the screen size 0.48
    comunityIcon = iconSize;
    logo_width = wurfl_screenWidth-4;
}
/////////////////////////// get the IP \\\\\\\\\\\\\\\\\\\\\\\\\\\
try {
    strIP = request.getRemoteHost();
}
catch(Exception ex) { strIP = ""; }

/////////////////////////// get the APN \\\\\\\\\\\\\\\\\\\\\\\\\\\
try {
    strApn = request.getHeader("x-msp-ag").trim();
}
catch(Exception ex) {

    strApn = "";
}

/////////////////////////// get the GSM NUMBER \\\\\\\\\\\\\\\\\\\\\\\\\\\
strGsm = (String)request.getAttribute("strGSM");
//------------------------------------------

/* CCS STYLES */
String  css_Logo                = "padding: 0px; margin: 0px; ",
        css_Img                 = "margin: 2px; ",
        css_Wrapper             = "width: 100%;background-color: #dedfe1; ",
        css_Wrapper_Allignment  = "center",
        css_widthMaintainer     = "width: 100%; background-color: "+divBgColor+"; ",
        css_Content             = "width: 100%; color: white; background-color: "+divBgColor+"; ",
        css_Content_Holder      = "width: 100%; text-align: center; padding-top: 5px; ",
        css_Logo_Div_Width      = "width: 100%; background-color: "+bodyBgColor+"; text-align: center; ",
        css_Content_Logo_Allignment = "right",
        css_SearchForm          = "width: 100%; text-align: center; background: "+divBgColor+"; padding: 0px; margin: 0px; ",
        css_SearchBox           = "color: #333333; width: "+ ((int)((wurfl_screenWidth*1.08) - logo_width)) +"px; border: none; margin:5px 0px 0px 0px;vertical-align: middle; ",
        css_SearchBtn           = "vertical-align: middle; border: 0px;margin:5px 0px 0px 0px;",
        css_navigator           = "padding-left: 5px; background-color: "+bodyBgColor+"; color: #239ec7; vertical-align: middle; line-height: 1.5; ",
        css_NavLinks            = "width: 100%; text-align: center; background-color: "+bodyBgColor+"; ",
        css_NewsBlock           = "padding: 5px 0px 0px 0px;",
        css_NewsBlockTableWidth = "width: 100%; ",
        css_NewsBlock_Para      = "width: 100%; padding-left: 3px; margin: 0px 0px 3px 0px; text-align: justify; ",
        css_NewsBlock_Heading   = "width: 99%; padding: 0px; margin: 0 0 3px 0px; background-color: #E7EEF3; text-align: left; font-weight: bold; border: 1px solid #2694E8; ", //E7EEF3-e4eded :: 2694E8-1789ab
        css_NewsBlock_div       = "padding-left: 80px; z-index: 1; ",
        css_NewsBlock_li        = css_NewsBlock_Para +"vertical-align: middle; list-style-image: url(images/blue-bullet.gif); list-style-type: circle; color: #43c4f2; ",
        css_NewsBlock_more      = "text-align: right; padding-right: 5px; font-weight: bold; padding-bottom: 3px; ",
        css_OtherTableWidth     = "width: 100%; ",
        css_MainLinks           = "",
        css_MainLinks_td        = "padding:2px; ",
        css_pagging             = "padding: 5px 0px; ",
        css_recommendationRightBullet = "background: "+bodyBgColor+" url("+context_Path+"/images/recomandation-right-bullet-spcr.jpg) repeat-y scroll right center; ",
        css_footer              = "background: "+bodyBgColor+"; ";

newsImageWidth = (int)(wurfl_screenWidth * 0.3);
mainButtonImgWidth = Math.min((int)(0.22 * wurfl_screenWidth), 67); // show 4 in a row


// Search Form Style Variations
if(!isTableSupport) {
    css_SearchBox = "color: #333333;' size='15";
}

//If phone Height is less then the required then show narrow strips
if(wurfl_screenHeight < 240) {
    isNarrowStrip = true;
    sImgFix = "100"; // If width is less than 240 then apply the small images patch
}

if(wurfl_screenWidth < 240) {
    sImgFix = "100";
}

// Check for Single Column phones
if (wurfl_screenWidth <= singelColumnWidth) {
    renderSingleColumn = true;
    sImgFix = "100";
}

// news header strip width calculation
if(isNarrowStrip) {
    narrowStripCenterImageHeight = "30"; // only possible values are 30, 36 or 48
    narrowStripFix = "-" + narrowStripCenterImageHeight;
    newsCenterTdWidth = wurfl_screenWidth - (94+23);
} else {
    narrowStripFix = "";
    narrowStripCenterImageHeight = "36"; // only possible values are 30, 36 or 48
    newsCenterTdWidth = wurfl_screenWidth - (113+27);
}

//if(renderSingleColumn || !isPercentWidthSupported) {
if(renderSingleColumn) {

    //iconSize = (int)(0.4 * wurfl_screenWidth); // 80% of the screen size
    if(isTableSupport) {
    	css_SearchBox = "color: #333333; width: "+ ((int)((wurfl_screenWidth*0.9) - 25)) +"px; border: none; ";
    }
    css_OtherTableWidth = "";
    css_NewsBlockTableWidth = "";
    newsCenterTdImgWidth = "width='"+ newsCenterTdWidth +"'";
    reommendationCenterTdWidth = Integer.toString(wurfl_screenWidth - (150+24)) +"px";
} else {
    newsCenterTdImgWidth = "width='100%'";
    reommendationCenterTdWidth = "100%";
}

if(isFixWidthPatch) {
    newsCenterTdImgWidth = "width='"+ newsCenterTdWidth +"'";
    reommendationCenterTdWidth = Integer.toString(wurfl_screenWidth - (150+24)) +"px";
}
/*
log.debug("ua: " + ua);
log.debug("Handset: " + strBrand +" - "+ strModel );
log.debug("Width: " + wurfl_screenWidth);
log.debug("Height: " + wurfl_screenHeight);
log.debug("xhtml_support_level: " + xhtml_support_level);
log.debug("mainButtonImgWidth: " + mainButtonImgWidth);
log.debug(" - - - - - - - - - - - - - - - - - - - - - - ");
*/
if(!bodyBgColor.equalsIgnoreCase("black")) {
    css_SearchBox += " border: 1px solid black; ";
    css_footer = "color: "+footerFgColor+"; padding: 5px 0; font-size: 85%; text-align: center; ";
    }

	String screenTitle = request.getRequestURI();
	int index =  screenTitle.indexOf("?");
	if(index > 0)
		screenTitle = screenTitle.substring(0, index);
	
	if(screenTitle.equals(context_Path+"/") || screenTitle.equals(context_Path+"/index.jsp"))
	{
		screenTitle = "Ufone - Home";
	}
	else {
		index =  screenTitle.indexOf("/", 1);	
		if(index == -1 || screenTitle.contains("includes/"))
		{
			screenTitle="Ufone";
		}
		else
		{
			screenTitle = "Ufone - "+ screenTitle.substring(1,screenTitle.indexOf("/",1));
		}
	}
%>
<head>
	<title><%=screenTitle%></title>	
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />                
	<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="HandheldFriendly" content="true" />
	<link rel="shortcut icon" href="<%=context_Path%>/images/favicon.ico" />
	<link rel="stylesheet" type="text/css" href="<%=context_Path+"/css/style.css"%>" />        
</head>
<body> 

<%
	if(wurfl_screenHeight<=200)
	{
		%>
		<div style="width:100%;height:23px; background-image:url('<%=request.getContextPath()%>/images/logo_bg_23.png') ;background-repeat: repeat-x;">
		<a href="<%=context_Path%>/index.jsp?ref=logo"><img align="right" style="padding-top:12px;padding-right:10px " src="<%=request.getContextPath()%>/images/logo_23.png" alt="ufone"/></a>
		</div>
		<%
	}
	else
	{
		%>
		<div style="width:100%;height:35px; background-image:url('<%=request.getContextPath()%>/images/logo_bg_s.png') ;background-repeat: repeat-x;">
		<a href="<%=context_Path%>/index.jsp?ref=logo"><img align="right" style="padding-top:4px;padding-right:10px " src="<%=request.getContextPath()%>/images/logo_s.png" alt="ufone"/></a>
		</div>
		<%
	}

%>

<div style ="clear:both;"></div>

<div id="wrapper" class="wrapper" style="<%=css_Wrapper%>" align="<%=css_Wrapper_Allignment%>">
	<div id="widthMaintainer" style="<%=css_widthMaintainer%>" align="left">
        <div style="margin:10px 0px 15px 0px;padding:10px 0px 15px 0px; text-align: center;">
            Your Handset is <%=strBrand +"  "+strModel%><br/><br/>
            <a style="color:#f58220;font-weight:bold;" href="http://172.16.13.24/ImiChat_S60_3rd_1.18.5_signed.sis">Download ImiChat</a>
        </div>
    
            </div>
        </div>
        
    </body>
    
</html>

<%
            wpb.LogVisit(strIP, thisPage, strGsm, strApn, strBrand, strModel, app, request.getQueryString());
%>